
/* Generated by Interface Builder */

#import "math.h"
#import "AreaRule.h"
float lastFrameRate = 10.0;

@implementation AreaRule

DPSTimedEntry teNumber=0;
static void calculate();

- init	
{	[super init];
	initTable(0, 0);
	//if (c_xw > C_XW)
		c_xw = C_XW;
	//if (c_yh > C_YH)
		c_yh = C_YH;
	return self;
}

void initTable(int phase, int dir)
{	int i, v, k=dir? 1: -1;
	static int lastPhase, lastDir=-5;
	if (phase == lastPhase && dir == lastDir)
		return;
	lastPhase = phase;
	lastDir = dir;
	for (i=0; i<NsineTable; i++)
	{	v = 7.499*(sin(2*i*M_PI/NsineTable) + 1.0);
		redTable  [(i+phase +   0*NsineTable/3)%NsineTable] = v;
		greenTable[(i+phase +   k*NsineTable/3)%NsineTable] = v;
		blueTable [(i+phase + 2*k*NsineTable/3)%NsineTable] = v;
}	}

- start:sender
{	Self = self;
	if (lastFrameRate <= 0)
		intiTimedEntry(-lastFrameRate);
	return self;
}

void intiTimedEntry(float frameRate)
{	if (frameRate == lastFrameRate)
		return;
	lastFrameRate = frameRate;
	if (teNumber)
		DPSRemoveTimedEntry(teNumber);
	teNumber=DPSAddTimedEntry(1/lastFrameRate, calculate, (void *)0, 2);
}

- stop:sender
{	if (teNumber)
	{	DPSRemoveTimedEntry(teNumber);
		teNumber = 0;
		lastFrameRate = -lastFrameRate;
	}
	return self;
}

static void calculate(DPSTimedEntry teNumbr, double now, char *userData)
{	[Self compute];
	[Self display];
}

- drawSelf:(const NXRect *)rects :(int)rectCount
{	NXSetColor(NXConvertRGBAToColor(1.0, 1.0, 1.0,   1.0));
	NXRectFill(&bounds);
	return self;
}

- Randomize :sender		{	return self;	}
- (void)compute					{}

@end
